import { Response, NextFunction } from 'express';
import { AuthenticatedRequest } from '../types/express';
import { EvaluationStatus } from '../types/evaluation';

// 定义参数类型作为替代
interface RequestParams {
  [key: string]: any;
}

export function handleStatusUpdate(
  req: AuthenticatedRequest<RequestParams>,
  statusUpdate: Partial<{status: EvaluationStatus}>
): void {
  if (req.body) {
    req.body = {
      ...req.body,
      ...statusUpdate
    };
  } else {
    req.body = statusUpdate;
  }
}

export function safeObjectId(id: string | undefined | null): string | null {
  if (!id) return null;
  return id;
}

export function createNextFunction(): NextFunction {
  return (error?: any) => {
    if (error) {
      throw error;
    }
  };
}

export function buildStatusUpdateRequest(
  req: AuthenticatedRequest<RequestParams>,
  res: Response,
  statusUpdate: Partial<{status: EvaluationStatus}>
): [AuthenticatedRequest<RequestParams>, Response, NextFunction] {
  handleStatusUpdate(req, statusUpdate);
  const next = createNextFunction();
  return [req, res, next];
}
